
//类
class Person{
    //字段 - 成员变量 - 定义在类的内部，方法的外部
    private String name;
    public int age;
    public double weight;

    //方法 - 函数
    public void eat(){
        System.out.println(name+"eat()");
    }
    public void setName(String myName){
        name=myName;
    }
    public String getName(){
        return name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", weight=" + weight +
                '}';
    }
}
public class TestDemo2 {
    public static void main(String[] args) {
        Person person=new Person();
        //person.name="qian";
        person.setName("qian");
        //System.out.println(person.name);
        System.out.println(person.getName());
    }
    public static void main1(String[] args) {
        //实例化一个对象，通过new关键字
        Person p1=new Person();
        //对象名.变量名
//        p1.name="qian";
//        p1.age=18;
//        p1.weight=50.5;
//        System.out.println(p1.name);
        //对象名.方法名
        p1.eat();
        Person p2=new Person();
        Person p3=new Person();
        Person p4=new Person();
        System.out.println(p1);
    }
}
